//
//  LLT_MenuTableViewController_LXH.m
//  CoderLLT
//
//  Created by 刘晓萌 on 15/12/21.
//  Copyright © 2015年 刘晓萌. All rights reserved.
//

#import "LLT_MenuTableViewController_LXH.h"
#import "UIViewController+REFrostedViewController.h"
#import "SDImageCache.h"
#import "AppDelegate.h"
#import "LLT_LoginViewController_LXM.h"
#import "REFrostedViewController.h"
#import "UIViewController+LLT_LoginAndRegist_LXM.h"
#import "LLT_MenuCell_LXM.h"
#import "LLT_ChangeNameViewController_LXH.h"
#import "ANNewsListViewController.h"
#import <AVOSCloud/AVOSCloud.h>
#import "LLT_UserInfo.h"
#import "LLT_SearchPlayerViewController_LXM.h"
@interface LLT_MenuTableViewController_LXH ()<UITableViewDataSource, UITableViewDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate,UIAlertViewDelegate>

@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UILabel *label;
@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) NSMutableArray *data1;
@property (nonatomic, strong) NSMutableArray *data2;
@property (nonatomic, strong) NSMutableArray *data3;
@property (nonatomic, strong) NSMutableArray *pics1;
@property (nonatomic, strong) NSMutableArray *pics2;
@property (nonatomic, strong) NSMutableArray *pics3;
@property (nonatomic, strong) NSMutableArray *bgpics;
@property (assign, nonatomic) BOOL scrollFlag;
@property (assign, nonatomic) BOOL onlineFlag;
@property (strong, nonatomic) UIImageView *scroollBGImage;
@property (assign, nonatomic) NSInteger scrollPageount;
@end

@implementation LLT_MenuTableViewController_LXH

#pragma mark --- dealloc
-(void)dealloc
{
    [self.imageView removeFromSuperview];
    [self.label removeFromSuperview];
    [self.scrollView removeFromSuperview];
    self.label = nil;
    self.scrollView = nil;
    self.imageView = nil;
    self.data1 = nil;
    self.data2 = nil;
    self.data3 = nil;
    self.pics1 = nil;
    self.pics2 = nil;
    self.pics3 = nil;
    self.bgpics = nil;
    [self.scroollBGImage removeFromSuperview];
    self.scroollBGImage = nil;
    
    
}

#pragma mark --- 视图加载完毕

- (void)viewDidLoad {
    self.view.alpha = 0.9;
    self.onlineFlag = [self isonLine];
    [super viewDidLoad];
    [self makeScrollView];
    [self makeView];
    [self creatTableView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark --- 页面设置
/**
 * 设置页面(调节亮度)
 */
-(void)makeView
{
    
    if (self.onlineFlag)
    {
        //初始化列表数据
        self.data1 = [NSMutableArray arrayWithObjects:@"管理角色",@"修改密码",@"切换背景",nil];
        self.pics1 = [NSMutableArray arrayWithObjects:@"mjuese",@"mmima",@"mqiehuan",nil];
        self.data2 = [NSMutableArray arrayWithObjects:@"个人收藏",@"其他趣闻", nil];
        self.pics2 = [NSMutableArray arrayWithObjects:@"mshoucan",@"mxinwen", nil];
    }
    else
    {
        self.data1 = [NSMutableArray arrayWithObjects:@"切换背景",nil];
        self.pics1 = [NSMutableArray arrayWithObjects:@"mqiehuan",nil];
        
        self.data2 = [NSMutableArray arrayWithObjects:@"其他趣闻", nil];
        self.pics2 = [NSMutableArray arrayWithObjects:@"mxinwen", nil];
    }
   
    self.data3 = [NSMutableArray arrayWithObjects:@"清除缓存",@"夜间模式",@"退出登录",@"免责声明",nil];
    
    //
    
    self.pics3 = [NSMutableArray arrayWithObjects:@"mclear",@"myejian",@"mclose",@"mshuoming",nil];
    
    //
    self.bgpics = [NSMutableArray arrayWithObjects:@"mbg1",@"mbg2",@"mbg3", nil];
    
}

/**
 * 设置scrollView
 */
-(void)makeScrollView{
    self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    self.scrollView.contentSize = CGSizeMake(WIDTH*3, HEIGHT);
    self.scrollView.backgroundColor = [UIColor grayColor];
    
    self.scroollBGImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, WIDTH*3, HEIGHT)];
    self.scroollBGImage.image = [UIImage imageNamed:@"mbg1"];
    
    [self.scrollView addSubview:self.scroollBGImage];
    [self.view addSubview:self.scrollView];
    self.scrollView.showsVerticalScrollIndicator = NO;
    self.scrollView.showsHorizontalScrollIndicator = NO;
    [self.view sendSubviewToBack:self.scrollView];
    [self.view bringSubviewToFront:self.tableView];

    [NSTimer scheduledTimerWithTimeInterval:0.025 target:self selector:@selector(scrollViewAutoScrooll) userInfo:nil repeats:YES];
}


#pragma mark --- tableView相关

/**
 * 设置tableView
 */
-(void)creatTableView
{
    //separatorColor 设置默认颜色
    self.tableView.separatorColor = [UIColor colorWithRed:150/255.0f green:161/255.0f blue:177/255.0f alpha:1.0f];
    //设置代理
    self.tableView.opaque = NO;
    self.tableView.scrollEnabled = NO;
    //设置背景颜色
    self.tableView.backgroundColor = [UIColor clearColor];
    [self.tableView registerNib:[UINib nibWithNibName:@"LLT_MenuCell_LXM" bundle:nil] forCellReuseIdentifier:@"Cell"];
    //设置头文件
    [self makeTableViewHeadView];
    self.tableView.tableFooterView = ({
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 150.0f)];
        view;
    });
    
    UIImageView *viewImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, HEIGHT)];
    viewImage.image = [UIImage imageNamed:@"showINFO"];
    [self.view addSubview:viewImage];
    [self.view sendSubviewToBack:viewImage];
    viewImage.alpha = 1;
}

/**
 * 设置tabelView头文件
 */
-(void)makeTableViewHeadView{
    
    self.tableView.tableHeaderView = ({
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 150.0f)];
        //如果在线
        [self makeHeadImage:[UIImage imageNamed:@"mhead"]];
        if (_onlineFlag) {
            AVUser *user =  [AVUser currentUser];
            NSData *data = [user objectForKey:@"userIcon"];
            UIImage *image = [UIImage imageWithData:data];
            if (image) {
              [self makeHeadImage:image];
            }
        }
        [self makeName];
        
        [view addSubview:self.imageView];
        [view addSubview:self.label];
        UIView *bgview = [[UIView alloc]initWithFrame:view.frame];
        bgview.backgroundColor = [UIColor blackColor];
        [view addSubview:bgview];
        bgview.alpha = 0.5;
        [view sendSubviewToBack:bgview];
        view;
    });
}

/**
 * 设置头像
 */
-(void)makeHeadImage:(UIImage *)image{
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(pickImage)];
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 40, 70, 70)];
    imageView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
    //
    NSData *imageData = UIImagePNGRepresentation(image);
  
    
    imageView.image = image;
    imageView.layer.masksToBounds = YES;
    imageView.layer.cornerRadius = imageView.frame.size.width/2;
    imageView.layer.borderColor = [UIColor whiteColor].CGColor;
    imageView.layer.borderWidth = 3.0f;
    imageView.layer.rasterizationScale = [UIScreen mainScreen].scale;
    imageView.layer.shouldRasterize = YES;
    imageView.clipsToBounds = YES;
    self.imageView = imageView;
    if (_onlineFlag) {
        self.imageView.userInteractionEnabled = YES;
        [self.imageView addGestureRecognizer:tap];
    }
    
}

/**
 * 设置昵称
 */
-(void)makeName
{
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(changeName)];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 120, 350, 24)];
    if (_onlineFlag) {
        AVUser *user = [AVUser currentUser];
        label.text =  user.username;
    }else
    {
        label.text = @"游客";
    }
    label.shadowColor = [UIColor blackColor];
    label.shadowOffset = CGSizeMake(0, -1.0);
    label.font = [UIFont fontWithName:@"HelveticaNeue" size:19];
    label.backgroundColor = [UIColor clearColor];
    label.textColor = [UIColor orangeColor];//[UIColor colorWithRed:62/255.0f green:68/255.0f blue:75/255.0f alpha:1.0f];
    [label sizeToFit];
    label.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
    self.label = label;
    if (_onlineFlag) {
        self.label.userInteractionEnabled = YES;
        [self.label addGestureRecognizer:tap];
    }
}


#pragma mark - Table view delegate
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)sectionIndex
{
    if (sectionIndex == 0)
        return 0;
    return 20;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    LLT_MenuCell_LXM *cell = [tableView cellForRowAtIndexPath:indexPath];
    NSString *title = cell.labelText.text;
    //1
    if ([title isEqualToString:@"管理角色"]) {
        [self setPlayer];
        return;
    }
    if ([title isEqualToString:@"修改密码"]) {
        [self presentViewController:[MainStoryBoard instantiateViewControllerWithIdentifier:@"changePassword"] animated:YES completion:nil];
        [self.frostedViewController hideMenuViewController];
        return;
    }
    if ([title isEqualToString:@"切换背景"]) {
        [self changScrollBackImage];
        return;
    }
    //2
    if ([title isEqualToString:@"个人收藏"]) {
        [self presentViewController:[MainStoryBoard instantiateViewControllerWithIdentifier:@"colloctionView"] animated:YES completion:nil];
        return;
    }
    if ([title isEqualToString:@"其他趣闻"]) {
        UIStoryboard *anStoryBoard = [UIStoryboard storyboardWithName:@"ANMain" bundle:nil];
        ANNewsListViewController *anewslist = [anStoryBoard instantiateViewControllerWithIdentifier:@"listVC"];
        [self presentViewController:anewslist animated:YES completion:^{
            nil;
        }];
        return;
    }
    //3
    if ([title isEqualToString:@"清除缓存"]) {
        [self clearCache];
        return;
    }
    if ([title isEqualToString:@"退出登录"]) {
        [self logout];
        return;
    }
    if ([title isEqualToString:@"免责声明"]) {
        [self showAlert:@"免责声明" andAlertString:@"本应用不用来赢利，发布的App内容源于互联网和个人搜集，仅用于技术分享，学习和交流，本应用内容版权归原App作者及其网站所有，特此声明"];
        return;
    }
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSInteger count = 0;
    switch (section) {
        case 0:
            count = self.data1.count;
            break;
        case 1:
            count = self.data2.count;
            break;
        case 2:
            count = self.data3.count;
            break;
        default:
            break;
    }
    return count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 38;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *cellIdentifier = @"Cell";
    LLT_MenuCell_LXM *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
    cell.iconImage.image = [UIImage imageNamed:@"headImage.png"];
    UIView *bgview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, cell.contentView.frame.size.height)];
    bgview.backgroundColor = [UIColor blackColor];
    [cell.contentView addSubview:bgview];
    [cell.contentView sendSubviewToBack:bgview];
    bgview.alpha = 0.8;
    cell.backgroundColor = [UIColor clearColor];
    NSInteger section = indexPath.section;
    NSInteger row = indexPath.row;
    switch (section) {
        case 0:
            cell.labelText.text = self.data1[row];
            cell.iconImage.image = [UIImage imageNamed:self.pics1[row]];
            break;
        case 1:
            cell.labelText.text = self.data2[row];
            cell.iconImage.image = [UIImage imageNamed:self.pics2[row]];
            break;
        case 2:{
            
            cell.labelText.text = self.data3[row];
            cell.iconImage.image = [UIImage imageNamed:self.pics3[row]];
            if ([cell.labelText.text isEqualToString:@"夜间模式"]) {
                cell.goImage.hidden = YES;
                UISwitch *swich = [[UISwitch alloc] initWithFrame:CGRectMake(250, 10, 50, 30)];
                cell.accessoryView = swich;
                [swich addTarget:self action:@selector(swichClick) forControlEvents:UIControlEventValueChanged];
                [swich  setOn:_swichOpen];
            }
        }
            break;
        default:
            break;
    }
    return cell;
}

-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0,WIDTH, 21)];
    UIView *bgview = [[UIView alloc]initWithFrame:view.bounds];
    bgview.backgroundColor = [UIColor blackColor];
    bgview.alpha = 0.55;
    [view addSubview:bgview];

    view.backgroundColor = [UIColor clearColor];
    return view;
}
#pragma mark --- 点击事件
/**
 * 点击头像/触发换图或者调用相机方法
 */
-(void)pickImage
{
    UIAlertController *sheetAction = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    UIImagePickerController *picker = [[UIImagePickerController alloc]init];
    picker.allowsEditing = YES;
    picker.delegate = self;
    [sheetAction addAction:[UIAlertAction actionWithTitle:@"选取照片" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        //NSLog(@"相册");
        picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
        [self presentViewController:picker animated:YES completion:nil];
    }]];
    
    [sheetAction addAction:[UIAlertAction actionWithTitle:@"拍摄照片" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
            picker.sourceType = UIImagePickerControllerSourceTypeCamera;
            [self presentViewController:picker animated:YES completion:nil];
        } else {
            //NSLog(@"相机不能用");
        }
    }]];
    
    [sheetAction addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        //NSLog(@"取消");
    }]];
    [self presentViewController:sheetAction animated:YES completion:nil];
}

/**
 * 调用相册结束
 */
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
    //NSLog(@"%@",info);
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    NSData *imageData = UIImageJPEGRepresentation(image, 0.1);
    self.imageView.image = image;
    [[AVUser currentUser] setObject:nil forKey:@"userIcon"];
    [[AVUser currentUser]  save];
    [[AVUser currentUser] setObject:imageData forKey:@"userIcon"];
    
    [[AVUser currentUser] saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        if (!succeeded) {
            [self showAlert:@"提 示" andAlertString:[NSString stringWithFormat:@"头像保存失败,原因%@",error.userInfo[@"error"]]];
        }
    }];
    [picker dismissViewControllerAnimated:YES completion:nil];
}


/**
 * 更改昵称
 */
-(void)changeName{
    
    LLT_ChangeNameViewController_LXH *llt = [MainStoryBoard instantiateViewControllerWithIdentifier:@"changeName"];
    llt.name = self.label.text;
    llt.block = ^(NSString *string){
        self.label.text = string;
    };
    
    [self presentViewController:llt animated:YES completion:nil];
}

#pragma mark --- implementation function / 功能实现

/**
 * 切换背景
 */

-(void)changScrollBackImage{
    static BOOL bggimagFlag;
    NSInteger pageNum = self.scrollPageount;
    if (pageNum+1>2) {
        bggimagFlag = YES;
    }else if(pageNum-1 < 0 ){
        bggimagFlag = NO;
    }
    if (bggimagFlag) {
        pageNum --;
    }else{
        pageNum ++;
    }
    self.scrollPageount = pageNum;
    self.scroollBGImage.image = [UIImage imageNamed:self.bgpics[pageNum]];
}

/**
 * 图片滚动
 */
-(void)scrollViewAutoScrooll{
    NSInteger x = self.scrollView.contentOffset.x;
    NSInteger y = self.scrollView.contentOffset.y;
    if (self.scrollFlag) {
        self.scrollView.contentOffset = CGPointMake(x - 1, y);
        if ( x<= 2 ){
            self.scrollFlag = NO;
        }
    }else{
        self.scrollView.contentOffset = CGPointMake(x + 1, y);
        if (x + 2 >= (self.scrollView.contentSize.width - self.view.frame.size.width)) {
            self.scrollFlag = YES;
        }
    }
}

/**
 * 登出功能
 */
-(void)logout{
    [self dismissViewControllerAnimated:YES completion:nil];
    [self.frostedViewController hideMenuViewController];
    //更改登录状态为NO
    NSUserDefaults *loginDefault = [NSUserDefaults standardUserDefaults];
    [loginDefault setBool:NO forKey:@"online"];
    
    [self presentViewController:getVC(@"loginVC") animated:YES completion:nil];
}

/**
 * 管理角色功能
 */
-(void)setPlayer{
    //[[NSUserDefaults standardUserDefaults] setBool:lock forKey:@"hasPlayer"];
    BOOL getPlayer = [[NSUserDefaults standardUserDefaults] boolForKey:@"hasPlayer"];
    __weak typeof (self) weakself = self;
    if (getPlayer) {
        [self showAlert:@"提 示" andAlertString:@"确定要重新绑定账号么" andHandler:^(UIAlertAction *action) {
            AVQuery *query = [AVQuery queryWithClassName:@"LLT_PlayerInfo"];
            NSDictionary *onlineUser =[[NSUserDefaults standardUserDefaults] dictionaryForKey:@"onlineUser"];
            [query whereKey:@"phoneNumber" equalTo:onlineUser[@"username"]];
            [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
                if (!error) {
                        [query deleteAllInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
                            if (succeeded) {
                                LLT_SearchPlayerViewController_LXM *spvc = getVC(@"searchPlayerVC");
                                [weakself presentViewController:spvc animated:YES completion:nil];
                            }else{
                                [weakself showAlert:@"删除失败" andAlertString:error.userInfo[@"error"]];
                            }
                        }];
                    }else{
                        [weakself showAlert:@"删除失败" andAlertString:error.userInfo[@"error"]];
                }
            }];
        }];
    }else{
        [weakself showAlert:@"提 示" andAlertString:@"请先到主页面绑定账号"];
    }
}

/**
 * 添加复杂点儿allert提示
 */
-(void)showAlert:(NSString *)alertTitle andAlertString:(NSString *)alertContent andHandler:(void (^ __nullable)(UIAlertAction *action))handler{
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:alertTitle message:alertContent preferredStyle:UIAlertControllerStyleAlert];
    if(handler){
        [alertVC addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:handler]];
        [alertVC addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil]];

    }else{
        [alertVC addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];

    }
            [self presentViewController:alertVC animated:YES completion:nil];
}







#pragma mark -- 缓存功能
/**
 * 垃圾清理功能
 */
-(void)clearCache
{
    NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)objectAtIndex:0];
    unsigned long long size = [self fileSizeAtPath:cachePath];
    NSString *contents = [NSString stringWithFormat:@"%@%.2fM,%@",@"当前有缓存",size/1024.0,@"清除有助于减少空间占有，但会导致加载之前浏览过的图片变慢，确定要清除？"];
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"清除缓存" message:contents delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    alert.alertViewStyle = UIAlertViewStyleDefault;
    [alert show];
    //NSLog(<#NSString * _Nonnull format, ...#>)
}

#pragma mark-UIAlertViewDelegate
/**
 * alert结束后调用
 */
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1)
    {
        _HUD = [[MBProgressHUD alloc] initWithView:self.view];
        [self.view addSubview:_HUD];
        _HUD.center = self.view.center;
        _HUD.minSize = CGSizeMake(135.0f, 135.0f);
        _HUD.mode = MBProgressHUDModeIndeterminate;
        _HUD.labelText = @"清除中。。。";
        [_HUD showWhileExecuting:@selector(clear) onTarget:self withObject:nil animated:YES];
    }
}
- (void)clear
{
    NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)objectAtIndex:0];
    NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:cachePath];
    for (NSString *p in files) {
        NSError *error;
        NSString *path = [cachePath stringByAppendingPathComponent:p];
        if ([[NSFileManager defaultManager]fileExistsAtPath:path]) {
            [[NSFileManager defaultManager]removeItemAtPath:path error:&error];
        }
    }
    [self clearCacheSuccess];
}
/**
 * 清理缓存成功
 */
-(void)clearCacheSuccess{
    sleep(2);
    _HUD.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"black_tips_ok.png"]];
    _HUD.mode = MBProgressHUDModeCustomView;
    _HUD.labelText = @"清除成功";
    sleep(1);
}
/**
 * 计算缓存大小
 */
-(long long)fileSizeAtPath:(NSString *)filePath
{
    NSFileManager *manager = [NSFileManager defaultManager];
    if ([manager fileExistsAtPath:filePath]) {
        return [[manager attributesOfItemAtPath:filePath error:nil]fileSize];
    }
    return 0;
}
#pragma mark -- 设置亮度
/**
 * 设置亮度
 */
- (void)swichClick{
    //明暗交替
    static  BOOL openNightMode = YES;
    //设置夜间模式覆盖页面
    AppDelegate *Adg = [[UIApplication sharedApplication] delegate];
    UIWindow *window = Adg.window;
    if (openNightMode){
        window.alpha = 0.5;
    }else{
        window.alpha = 1;
    }
    openNightMode = !openNightMode;
}







/*
 // Override to support conditional editing of the table view.
 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
 // Return NO if you do not want the specified item to be editable.
 return YES;
 }
 */

/*
 // Override to support editing the table view.
 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
 if (editingStyle == UITableViewCellEditingStyleDelete) {
 // Delete the row from the data source
 [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
 } else if (editingStyle == UITableViewCellEditingStyleInsert) {
 // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
 }
 }
 */

/*
 // Override to support rearranging the table view.
 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
 }
 */

/*
 // Override to support conditional rearranging of the table view.
 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
 // Return NO if you do not want the item to be re-orderable.
 return YES;
 }
 */

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
